package com.example.myapplication.module1.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.TextView
import com.example.myapplication.R
import com.example.myapplication.databinding.ItemScheduleBinding
import com.example.myapplication.entity.ScheduleBean
import com.example.mylibrary.adapter.BaseRecyclerAdapter
import com.example.mylibrary.utils.UiTools

class ScheduleAdapter(context: Context) : BaseRecyclerAdapter<ItemScheduleBinding>(context) {

    var scheduleBeanList = mutableListOf<ScheduleBean>()
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun getBinding(
        inflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemScheduleBinding {
        return ItemScheduleBinding.inflate(inflater, parent, false)
    }

    override fun getViewHolder(baseViewHolder: BaseViewHolder) {
        viewBinding.cbCheck.setOnClickListener(object : View.OnClickListener {
            override fun onClick(v: View?) {
                val position = baseViewHolder.itemView.tag as Int
                val scheduleBean = scheduleBeanList[position]
                scheduleBean.isCheck = viewBinding.cbCheck.isChecked
            }
        })
    }

    @SuppressLint("SetTextI18n")
    override fun bindHolder(holder: BaseViewHolder, position: Int) {
        val scheduleBean = scheduleBeanList[position]
        viewBinding.tvScheduleTitle.text = scheduleBean.title
        viewBinding.tvScheduleTime.text =
            "${UiTools.getString(R.string.remindTime)}${scheduleBean.startdate} ${scheduleBean.starttime}"
        viewBinding.cbCheck.isChecked = scheduleBean.isCheck
    }

    override fun getItemCount(): Int {
        return scheduleBeanList.size
    }


}
